package com.sebiotec.ambassador.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;

import com.allen.library.interceptor.Transformer;
import com.allen.library.observer.CommonObserver;
import com.sebiotec.ambassador.model.response.MessageDetailResponse;
import com.sebiotec.ambassador.net.BookApiHelper;
import com.sebiotec.ambassador.ui.view.LoadingDialog;
import com.sebiotec.basecommon.utils.constant.SjmConstant;
import com.sebiotec.basecommon.utils.language.LocalManageUtil;
import com.sebiotec.basecommon.utils.tools.ActivityTool;
import com.sebiotec.basecommon.utils.tools.SPUtils;


import java.util.HashMap;

public class MessageDetailsViewModel extends AndroidViewModel {
    public MessageDetailsViewModel(@NonNull Application application) {
        super(application);
    }
    public MyMessageDetailDataCallBack mDataCallBack;

    //数据回调接口
    public interface MyMessageDetailDataCallBack<T> {
        void onDataSuccessCallBack(T t);
        void onDataFailCallBack(T t);
    }


    //
        public void  getData(String Bookid,MyMessageDetailDataCallBack<Object> mDataCallBack){
            LoadingDialog loadingDialog = new LoadingDialog(ActivityTool.getInstance().getLastActivity());
            HashMap<String,Object> map=new HashMap<String, Object>();
            map.put("LoginId", SPUtils.get(SjmConstant.LOGINID,""));
            map.put("Token", SPUtils.get(SjmConstant.TOKEN,""));
            map.put("Lang", LocalManageUtil.getSMJSetLanguageLocales(ActivityTool.getInstance().getLastActivity()));

            BookApiHelper.geRadomApi()
                    .getMessageDetail(map,Bookid)
                    .compose(Transformer.<MessageDetailResponse>switchSchedulers(loadingDialog))
                    .subscribe(new CommonObserver<MessageDetailResponse>() {
                        @Override
                        protected void onError(String errorMsg) {
                            mDataCallBack.onDataFailCallBack(errorMsg);
                        }

                        @Override
                        protected void onSuccess(MessageDetailResponse s) {

                            mDataCallBack.onDataSuccessCallBack(s);
                        }
                    });
    }


}
